package com.logger;

import java.io.File;

import org.apache.commons.io.FilenameUtils;

class FileName {

    private static final String EXTENSION_SEP = ".";
    private final File          file;
    private final StringBuilder content;
    {
        this.content = new StringBuilder();
    }

    public FileName(final File file) {
        this.file = file;
    }

    public FileName(final String pathname) {
        this(new File(pathname));
    }

    public String getExtension() {
        return FileName.getExtension(this.file);
    }

    public static String getExtension(final File _file) {
        final String fileName = _file.getName();
        return FileName.getExtension(fileName);
    }

    public static String getExtension(final String fileName) {
        final int dot = fileName.lastIndexOf(FileName.EXTENSION_SEP);
        return fileName.substring(dot + 1);
    }

    public String getFileName() {
        final boolean withExtension = true;
        return this.getFileName(withExtension);
    }

    public String getFileName(final boolean withExtension) {
        return FileName.getFileName(this.file, withExtension);
    }

    public static String getFileName(final File _file) {
        final boolean withExtension = true;
        return FileName.getFileName(_file, withExtension);
    }

    public static String getFileName(final File _file, final boolean withExtension) {
        if (withExtension) {
            return _file.getName();
        } else {
            final String removeExtension = FilenameUtils.removeExtension(_file.getName());
            return removeExtension;
        }

    }

    public String getPath() {
        return this.file.getPath();
    }

    public File getFile() {
        return this.file;
    }

    public StringBuilder getContent() {
        return this.content;

    }
}
